package operate;

import book.BookList;

import java.util.Scanner;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 33013
 * Date: 2023-03-23
 * Time: 22:22
 */
public class DeLOperate implements Ioperate{
    @Override
    public void work(BookList bookList) {
        System.out.println("请输入要删除的书名");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int dex = -1;
        for (int i = 0; i < bookList.getBooknumber(); i++) {
            if (bookList.getBookList()[i].getName().equals(name)){
                dex = i;
                break;
            }
        }
        if (dex == -1){
            System.out.println("查无此书");
            return;
        }
        for (int i = dex; i < bookList.getBooknumber() - 1; i++) {
            bookList.getBookList()[i] = bookList.getBookList()[i + 1];
            bookList.setBooknumber(bookList.getBooknumber() - 1);
        }
        System.out.println("删除成功");
    }
}
